/**
 * @author Tobias Boehm
 *
 * 16.05.2011
 */
package org.anddev.andengine.extension.tbsengine.message.client.preparematch;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.UUID;

import org.anddev.andengine.extension.tbsengine.message.ICopyable;
import org.anddev.andengine.extension.tbsengine.message.client.AbsClientMatchMessage;

/**
 * This client message should be used to indicate whether a player is ready to 
 * play the match or not.
 * 
 * @author Tobias Boehm
 *
 */
public class ClientToggleReadyToPlayMessage extends AbsClientMatchMessage implements ICopyable<ClientToggleReadyToPlayMessage> {

	private boolean mReady = false;
	
	
	/* (non-Javadoc)
	 * @see org.anddev.andengine.extension.multiplayer.protocol.adt.message.IMessage#getFlag()
	 */
	@Override
	public short getFlag() {
		
		return FLAG_CLIENT_TOGGLE_READY_TO_PLAY_ANNOUNCEMENT;
	}
		
	@Override
	protected void onReadTransmissionClientMatchData(final DataInputStream pDataInputStream) throws IOException {
		
		this.mReady = pDataInputStream.readBoolean();
		
	}

	@Override
	protected void onWriteTransmissionClientMatchData(final DataOutputStream pDataOutputStream) throws IOException {
		
		pDataOutputStream.writeBoolean(this.mReady);
	}

	/**
	 * @param mReady the mReady to set
	 */
	public void setReady(boolean mReady) {
		this.mReady = mReady;
	}

	/**
	 * @return the mReady
	 */
	public boolean isReady() {
		return mReady;
	}
	
	public void setMatchID(final UUID pMatchID){
		
		this.mMatchID = pMatchID;
	}

	@Override
	public ClientToggleReadyToPlayMessage copy() {
		
		final ClientToggleReadyToPlayMessage copy = new ClientToggleReadyToPlayMessage();
		
		copy.mPlayerID = this.mPlayerID;
		copy.mReady = this.mReady;
		copy.mMatchID = this.mMatchID;
		
		return copy;
	}
}
